<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<h1>BMI测试</h1>
<form>
    身高:<input type="text" name="height" placeholder="身高(米)"><br>
    体重:<input type="text" name="weight" placeholder="体重(kg)"><br>
    <input type="button" value="测试" @click="test()">
    <h2>测试结果:{{info}}</h2>
</form>

<!--引入axios和vue-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.js"></script>

<script>
    let v = new Vue({
        el:"form",
        data:{
            info:""
        },
        methods:{
            test:function () {
                //发起异步请求
                let data = new FormData(document.querySelector("form"));
                axios.post("/bmi",data).then(function (response) {
                    //把服务器返回的数据直接显示在页面中
                    v.info = response.data;
                })
            }
        }

    })


</script>

</body>
</html>